/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sunsite.action;

import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import sunsite.service.MessageService;
import sunsite.tools.ContextHelper;

/**
 *
 * @author mg
 */
public class Messager extends ActionSupport{
    public static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Messager.class);
    private List<sunsite.po.Message> messages;
    private int pageCount;
    private int pageNow = 1;

    public int getPageNow() {
        return pageNow;
    }

    public void setPageNow(int pageNow) {
        this.pageNow = pageNow;
    }

    public List<sunsite.po.Message> getMessages() {
        return messages;
    }

    public int getPageCount() {
        return pageCount;
    }
    private MessageService messageService;

    public void setMessageService(MessageService messageService) {
        this.messageService = messageService;
    }

    @Override
    public String execute() throws Exception {
//        HttpServletRequest request = ServletActionContext.getRequest();
//        HttpServletResponse response = null;
//        response = ServletActionContext.getResponse();
//        request.setCharacterEncoding("utf-8");
//        response.setContentType("text/html;charset=utf-8");
        pageCount = messageService.getMessagePages();
        ContextHelper.getRequest().put("pageCount", pageCount);
        messages = messageService.getMessage(pageNow);
        return SUCCESS;
    }


}
